Skip to content

chore: remove metaId fallback from AwsQldbLedger after backfill#117

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/backfill-entryid-in-qldb-docs
Draft

chore: remove metaId fallback from AwsQldbLedger after backfill#117
Copilot wants to merge 2 commits intomainfrom
copilot/backfill-entryid-in-qldb-docs

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 20, 2026

All QLDB documents have been backfilled with an explicit entryId field, so the metaId fallback code path introduced for backward compatibility with pre-migration documents can be removed.

AwsQldbLedger.kt

  • resolveEntryId() — drops the metaId fallback branch; now reads entryId directly or returns ""
  • getHistory() query — removes h.metadata.id AS metaId projection; only h.metadata.txTime AS txTime and h.data.* are selected
// Before
internal fun resolveEntryId(struct: IonStruct): String =
    (struct.get("entryId") as? IonText)?.stringValue()
        ?: (struct.get("metaId") as? IonText)?.stringValue()
        ?: ""

// After
internal fun resolveEntryId(struct: IonStruct): String =
    (struct.get("entryId") as? IonText)?.stringValue() ?: ""

AwsQldbLedgerEntryResolutionTest.kt

  • Removes the two tests that validated metaId fallback behaviour (falls back to metaId when entryId is missing, ignores non-IonText entryId field and falls back to metaId)
  • Updates remaining resolveEntryId tests to no longer reference metaId
  • Adds resolveEntryId returns empty string when entryId is not an IonText to retain type-mismatch coverage without the fallback expectation

Copilot AI changed the title [WIP] Create and execute QLDB document migration to backfill entryId field chore: remove metaId fallback from AwsQldbLedger after backfill Apr 20, 2026
Copilot AI requested a review from MaximumTrainer April 20, 2026 17:48
@MaximumTrainer MaximumTrainer requested review from Copilot and removed request for MaximumTrainer April 20, 2026 17:48
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes the backward-compatibility metaId fallback in the QLDB ledger adapter after a production backfill ensured all documents now carry an explicit entryId.

Changes:

  • Remove metaId projection from the QLDB history(FactLedger) query.
  • Simplify resolveEntryId() to only read entryId (or return empty string).
  • Update/trim tests to drop metaId fallback expectations while keeping type-mismatch coverage.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
backend/src/main/kotlin/com/factstore/adapter/outbound/AwsQldbLedger.kt Removes metaId projection and drops metaId fallback in resolveEntryId() used by history reads.
backend/src/test/kotlin/com/factstore/adapter/outbound/AwsQldbLedgerEntryResolutionTest.kt Updates tests to align with removal of metaId fallback and keeps coverage for missing/wrong-typed entryId.

// fallback branch (the `?: struct.get("metaId")` path inside it) and the metaId
// projection from the SELECT above. The resolveEntryId behaviour is covered by
// AwsQldbLedgerEntryResolutionTest.
val resolvedEntryId = resolveEntryId(struct)
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getHistory() now relies solely on the explicit entryId. If production data is not fully backfilled (or a future write omits entryId), this will silently create LedgerEntry objects with entryId == "", which can break clients and makes diagnosing the bad document difficult. Consider failing fast (e.g., throw/log and skip the revision) when resolveEntryId(struct) returns blank, so incomplete backfills are detected immediately rather than producing invalid entries.

Suggested change
val resolvedEntryId = resolveEntryId(struct)
val resolvedEntryId = resolveEntryId(struct)
if (resolvedEntryId.isBlank()) {
log.error(
"QLDB history revision for record {} is missing required entryId: {}",
recordId,
struct
)
throw IllegalStateException("QLDB history revision for record $recordId is missing required entryId")
}

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chore: create and execute QLDB document migration to backfill entryId field

3 participants